package com.ftg.learn.chapter10.example;

import java.util.function.Consumer;

/**
 * 计算
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/1/31 下午2:58
 */
public class MyCompute {

    public static void main(String[] args) {
        Operation op = new OperationImpl();
        int sum = op.compute(3, 2, new Sub());
        System.out.println(sum);


        int sum1 = op.compute(3, 2, new Deel() {

            @Override
            public int deep(int x, int y) {
                return x * y;
            }
        });

        System.out.println(sum1);

        Deel deel = (x, y) -> x / y;
        int sum2 = op.compute(3, 2, deel);

        //Lambda表达式
        final int[] t = {0};
        int sum3 = op.compute(23, 34, (x, y) -> {
            int sumN = x + y;
            t[0] = sumN;
            return sumN;
        });
        System.out.println(sum3);


        IDemo iDemo01 = (a,b)->{return 2f;};
        IDemo iDemo02 = (a,b)->2f;
        IDemo iDemo03 = (a,b)-> new Float(a+b);
        //使用lambda标准 ，要求是一个接口 ，而且接口里面只能有一个外部调用或者重写的抽象方法
        IDemo iDemo04 = (a,b)-> {
            //就怎么写
            if(a < 10){
                return a + b;
            }else if(a  < 30){
                return a - b;
            }else{
                return 0;
            }
        };

        float f = iDemo04.ttt(2,3);
        System.out.println(f);

        iDemo04.abc();
    }



}
